package com.smartapps2020.web.bootstrap;

import java.io.FileInputStream;

public class JettyBootstrap {

	//private final static int JETTY_PORT = Integer.parseInt(System.getProperty("smartapps.port"));
	 private final int port;
	 private final String contextPath;
	 private final String workPath;
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		JettyBootstrap jb = new JettyBootstrap();
		
		/*
		Server server = new Server();
        SocketConnector connector = new SocketConnector();
       
        // Set some timeout options to make debugging easier.
        connector.setMaxIdleTime(1000 * 60 * 60);
        connector.setSoLingerTime(-1);
        connector.setPort(JETTY_PORT);
        server.setConnectors(new Connector[] { connector });

        WebAppContext context = new WebAppContext();
        context.setServer(server);
        context.setContextPath("/");

        ProtectionDomain protectionDomain = JettyBootstrap.class.getProtectionDomain();
        URL location = protectionDomain.getCodeSource().getLocation();
        context.setWar(location.toExternalForm());
       
        server.addHandler(context);
        try {
            server.start();
            System.out.println("*** Smartapps Framework STARTED on port:[" + JETTY_PORT + "] ***");
            System.in.read();
            server.stop();
            server.join();
          } catch (Exception e) {
            e.printStackTrace();
            System.exit(100);
          }
        */

	}
	public JettyBootstrap(){
		try{
			System.out.println("Constructor:JettyBootstrap():");
			String configFile = System.getProperty("config", "jetty.properties");
			System.getProperties().load(new FileInputStream(configFile));
		}catch(Exception eIgnored){
			System.out.println("Exception:eIgnored:");
		}
		
		port = Integer.parseInt(System.getProperty("jetty.port", "8080"));
		contextPath = System.getProperty("jetty.contextPath", "/");
		workPath = System.getProperty("jetty.workDir", null);
		
		System.out.println("port: "+port);
		System.out.println("contextPath: "+contextPath);
		System.out.println("workPath: "+workPath);
	}

}
